package com.lagou.serialize;

import com.alibaba.fastjson.JSON;

import java.io.IOException;
/**
 * @ClassName: JSONSerializer
 * @Description: 采用JSON的方式，定义JSONSerializer的实现类:（其他序列化方式，可以自行实现序列化接口）
 * @Version: v1.0.0
 * @Author: chendong
 * @Date: 2021/1/9
 * Modification History:
 * Date             Author      Version     Description
 * -------------------------------------------------------------
 * 2021/1/9         chendong       v1.0.0         创建
 */

public class JSONSerializer implements Serializer {

    @Override
    public byte[] serialize(Object object) throws IOException {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(Class<T> clazz, byte[] bytes) throws IOException {
        return JSON.parseObject(bytes, clazz);
    }
}
